package com.galaxy.product.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.galaxy.common.core.domain.R;
import com.galaxy.common.core.validate.AddGroup;
import com.galaxy.common.core.validate.EditGroup;
import com.galaxy.common.log.annotation.Log;
import com.galaxy.common.log.enums.BusinessType;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.product.domain.ProductFavorite;
import com.galaxy.product.domain.bo.ProductFavoriteBo;
import com.galaxy.product.domain.vo.ProductFavoriteVo;
import com.galaxy.product.service.IProductFavoriteService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商品收藏Controller
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/favorite")
public class ProductFavoriteApiController {

    private final IProductFavoriteService productFavoriteService;

    /**
     * 查询商品收藏列表
     */
    @GetMapping("/list")
    public TableDataInfo<ProductFavoriteVo> list(ProductFavoriteBo bo, PageQuery pageQuery) {
        return productFavoriteService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取商品收藏详细信息
     */
    @GetMapping("/{id}")
    public R<ProductFavoriteVo> getInfo(@PathVariable Long id) {
        return R.ok(productFavoriteService.queryById(id));
    }

    /**
     * 新增商品收藏
     */
    @Log(title = "商品收藏管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ProductFavoriteBo bo) {
        productFavoriteService.insertProductFavorite(bo);
        return R.ok();
    }

    /**
     * 修改商品收藏
     */
    @Log(title = "商品收藏管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> update(@Validated(EditGroup.class) @RequestBody ProductFavoriteBo bo) {
        productFavoriteService.updateProductFavorite(bo);
        return R.ok();
    }

    /**
     * 删除商品收藏
     */
    @Log(title = "商品收藏管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id) {
        productFavoriteService.delete(id);
        return R.ok();
    }

    /**
     * 批量删除商品收藏
     */
    @Log(title = "商品收藏管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch/{ids}")
    public R<Void> deleteBatch(@PathVariable Long[] ids) {
        productFavoriteService.deleteWithValidByIds(ids,  true);
        return R.ok();
    }

}
